package a08_StringDemo;

/**
 * @Author quan
 * @Description 字符串的拼接:输入为数组int[] arr = {1,2,3}，输出为[1,2,3]
 * @Date 2023/1/29 23:40
 */
public class StrConcat {
    public static void main(String[] args) {
        int [] arr = {1,2,3};
        String str = ToString(arr);
        System.out.println(str);
    }
    //拼接的方法
    public static String ToString(int[] arr){
        //安全校验
        if(arr == null){
            return "";
        }
        if(arr.length == 0 ){
            return "[]";
        }
        String result = "[";
        for (int i = 0; i < arr.length; i++) {
            if(i == arr.length - 1){
                result+=arr[i];
            }else{
                result+=arr[i]+",";
            }
        }
        result+="]";
        return result;
    }
}
